package hot100.logos21To30;

import hot100.datastruct.ListNode;

/**
 * @author logos
 * date 2025/7/13 11:15
 * @version v1.0
 * @Package hot100.logos21To30
 */
public class logos30 {

    /**
     * 30.两两交换链表中的节点
     * https://leetcode.cn/problems/swap-nodes-in-pairs/?envType=study-plan-v2&envId=top-100-liked
     */
    public ListNode swapPairs(ListNode head) {
        ListNode dummyHead = new ListNode(0, head);
        ListNode a = dummyHead;
        ListNode b = head;
        while (b != null && b.next != null) {
            ListNode c = b.next;
            ListNode d = c.next;
            a.next = c;
            c.next = b;
            b.next = d;
            a = b;
            b = d;
        }
        return dummyHead.next;
    }
}
